﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace dbproj
{
    public partial class Form6 : Form
    {
        public Form6()
        {
            InitializeComponent();
            Table();
        }

        /// <summary>
        /// 删除按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            string SId, Text;
            SId = dataGridView1.SelectedCells[0].Value.ToString();
            Text = dataGridView1.SelectedCells[1].Value.ToString();
            string sql = "delete from Message where SId ='" + SId + "'and Text ='" + Text + "'";
            Dao dao = new Dao();
            dao.Execute(sql);
            Table();
        }

        public void Table()
        {
            dataGridView1.Rows.Clear();
            string sql = "select * from Message";
            Dao dao = new Dao();
            IDataReader dr = dao.read(sql);
            while (dr.Read())
            {
                string a, b;
                a = dr["SId"].ToString();
                b = dr["Text"].ToString();
                string[] str = { a, b};
                dataGridView1.Rows.Add(str);
            }
            dr.Close();//关闭读取
        }
    }
}
